package com.siloam.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.siloam.module.Role;
import com.siloam.service.RoleService;
import com.siloam.vo.RoleVO;

@Controller
@RequestMapping("/web/role/role.do")
public class RoleController extends BaseController{

	@Resource
	private RoleService roleService;

	public RoleService getRoleService() {
		return roleService;
	}

	public void setRoleService(RoleService roleService) {
		this.roleService = roleService;
	}
	
	@RequestMapping(params="method=listRoles")
	@ResponseBody
	public List<RoleVO> listRoles(){
		return roleService.findAll();
	}
	
	@RequestMapping(params="method=add")
	@ResponseBody
	public String addRole(Role role){
		roleService.add(role);
		return SUCCESS;
	}
	
	@RequestMapping(params="method=initEdit")
	public String initEdit(int id, ModelMap model){
		Role role = roleService.load(id);
		model.put("role", role);
		return "/web/role/editRole";
	}
	
	@RequestMapping(params="method=update")
	@ResponseBody
	public String saveEdit(Role role){
		roleService.update(role);
		return SUCCESS;
	}
	
	@RequestMapping(params="method=delete")
	@ResponseBody
	public String delete(String ids){
		roleService.delete(ids);
		return SUCCESS;
	}
	
}
